package com.hmsm.server.tag;

import java.io.IOException;
import java.text.DecimalFormat;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.lang.StringUtils;

public class MoneyFormatTag extends BodyTagSupport {
	private static final long serialVersionUID = 1L;
	private String value;

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
	
	public int doStartTag() throws JspException {
		return EVAL_BODY_BUFFERED;//意思是将bodycontent传进来
	}
	
	public int doEndTag() throws JspException {
		// 得到标签体内容
		String content = this.getBodyContent().getString();
		if (StringUtils.isNotBlank(content)) {
			DecimalFormat df = new DecimalFormat("###,##0.00");
			content = df.format(Double.valueOf(content));
		}
		JspWriter out = this.pageContext.getOut();
		try {
			out.print(content);
		} catch (IOException e) {
			throw new RuntimeException("Tag error:<hmsm:money />");
		}
		return super.doStartTag();
	}
}
